# write a function calculate greeks of an european option

import math
from scipy.stats import norm


def greeks(S, K, T, r, sigma, option_type):
    d1 = (math.log(S / K) + (r + sigma**2 / 2) * T) / (sigma * math.sqrt(T))
    d2 = d1 - sigma * math.sqrt(T)
    if option_type == "call":
        return S * norm.cdf(d1) - K * math.exp(-r * T) * norm.cdf(d2)
    elif option_type == "put":
        return K * math.exp(-r * T) * norm.cdf(-d2) - S * norm.cdf(-d1)
    else:
        raise ValueError("option_type must be 'call' or 'put'")


# output an example using function greeks

S = 100
K = 100
T = 1
r = 0.05
sigma = 0.2
option_type = "call"
print(greeks(S, K, T, r, sigma, option_type))
option_type = "put"
print(greeks(S, K, T, r, sigma, option_type))
